package wangm.service;

import wangm.bean.Activity;
import wangm.bean.ActivtiyQueryParameter;
import wangm.bean.Pagination;
import wangm.repository.ActivityRepository;
import wangm.util.RandomUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 活动serviceImp
 *
 * @author zk
 * @since 2018/5/11
 */
@Service
public class ActivityServiceImp {
    /**
     * static logger
     */
    private static Logger logger = LoggerFactory.getLogger(ActivityServiceImp.class);
    /**
     *
     */
    @Autowired
    private ActivityRepository activityRepository;

    /**
     * 添加活动
     *
     * @param activity 活动
     */
    public void add(Activity activity){
        activity.setId(RandomUtil.getUUID());
        activity.setCreateTime(new Date());
        activity.setStatus("1");
        activity.setPermit("0");
        activityRepository.add(activity);
    }

    /**
     * 删除活动
     *
     * @param id 获取id
     */
    public void remove(String id){
        activityRepository.remove(id);
    }

    /**
     * 更新活动
     *
     * @param activity activity
     */
    public void update(Activity activity){
        activityRepository.update(activity);
    }

    /**
     * 获取list列表
     *
     * @param queryParameter queryParameter
     * @param pagination pagination
     * @return list
     */
    public List<Activity> getList(ActivtiyQueryParameter queryParameter, Pagination<Activity> pagination){
        if(queryParameter == null){
            queryParameter = new ActivtiyQueryParameter();
        }
        return activityRepository.getList(queryParameter,pagination);
    }
}
